import {Injectable} from '@angular/core';
import {Recruiter} from '../types/resp/Recruiter';
import {RecruiterForm} from '../types/req/RecruiterForm';
import {Result} from '../types/result';
import MockApi from '../api/mockApi';
import {map, Observable} from 'rxjs';
import type {Response} from '../types/response';
import {Page} from '../types/page';
import {RecruiterQueryForm} from '../types/req/RecruiterQueryForm';

@Injectable({
  providedIn: 'root'
})
export class RecruiterService {
  recruiters: Recruiter[] = [
    {"id":1,"enterpriseId":4,"enterpriseName":"江洋科技","username":"zhangwei","name":"张伟","password":"zhangwei123","contactPhone":"13800138000","email":"zhangwei@tencent.com","createTime":"2024-12-26 22:43:13","modifyTime":"2024-07-11 22:43:13"},
    {"id":2,"enterpriseId":4,"enterpriseName":"腾王科技","username":"liumei","name":"刘梅","password":"liumei456","contactPhone":"13800138001","email":"liumei@tencent.com","createTime":"2024-09-14 22:43:13","modifyTime":"2024-09-05 22:43:13"},
    {"id":3,"enterpriseId":4,"enterpriseName":"快讯科技","username":"wangli","name":"王丽","password":"wangli789","contactPhone":"13800138002","email":"wangli@tencent.com","createTime":"2024-03-07 22:43:13","modifyTime":"2024-04-28 22:43:13"},
    {"id":4,"enterpriseId":4,"enterpriseName":"腾讯科技","username":"chengang","name":"陈刚","password":"chengang101","contactPhone":"13800138003","email":"chengang@tencent.com","createTime":"2024-10-21 22:43:13","modifyTime":"2024-06-14 22:43:13"},
    {"id":5,"enterpriseId":3,"enterpriseName":"阿里巴巴","username":"lixia","name":"李霞","password":"lixia202","contactPhone":"13800138004","email":"lixia@alibaba.com","createTime":"2024-11-02 22:43:13","modifyTime":"2024-08-05 22:43:13"}
  ];
  constructor() {
  }

  save (recruiterForm: RecruiterForm): Observable<Result<void>> {
    console.log('recruiterApi save params', recruiterForm)
    return MockApi.operateSuccessfully().pipe(
      map((response: Response<Result<void>>) => response.data)
    );
  }

  find (recruiterQueryForm: RecruiterQueryForm): Observable<Result<Page<Recruiter>>> {
    console.log('recruiterApi find params', recruiterQueryForm)
    return MockApi.queryPageSuccessfully(this.recruiters).pipe(
      map((response: Response<Result<Page<Recruiter>>>) => response.data)
    );
  }

  findById (id: number): Observable<Result<Recruiter>> {
    console.log('recruiterApi findById id', id)
    let target = {}
    for (const a of this.recruiters) {
      if (a.id === id) {
        target = a
      }
    }
    return MockApi.operateSuccessfullyWithData(target).pipe(
      map((response: Response<Result<Recruiter>>) => response.data)
    );
  }

  del (id: number): Observable<Result<void>> {
    console.log('recruiterApi del id', id)
    return MockApi.operateSuccessfully().pipe(
      map((response: Response<Result<void>>) => response.data)
    );
  }
}
